#!/bin/sh
# Run from OPENFOAM src/ directory only
cd "${0%/*}" || exit
wmake -check-dir "$WM_PROJECT_DIR/src" 2>/dev/null || {
    echo "Error (${0##*/}) : not located in \$WM_PROJECT_DIR/src"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
if [ -f "$WM_PROJECT_DIR"/wmake/scripts/AllwmakeParseArguments ]
then  . "$WM_PROJECT_DIR"/wmake/scripts/AllwmakeParseArguments || \
    echo "Argument parse error";
else
    echo "Error (${0##*/}) : WM_PROJECT_DIR appears to be incorrect"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
fi

#------------------------------------------------------------------------------

wmakeLnInclude -u OpenFOAM
wmakeLnInclude -u OSspecific/"${WM_OSTYPE:-POSIX}"

OSspecific/"${WM_OSTYPE:-POSIX}"/Allwmake $targetType $*

case "$WM_COMPILER" in
Mingw*)
    # Pstream/OpenFOAM cyclic dependency
    # 1st pass: link as Pstream as single .o object
    WM_MPLIB=dummy Pstream/Allwmake libo
    FOAM_LINK_DUMMY_PSTREAM=libo wmake $targetType OpenFOAM

    # 2nd pass: link Pstream.dll against libOpenFOAM.dll
    Pstream/Allwmake $targetType $*

    # Force relink libOpenFOAM.dll against libPstream.dll
    OpenFOAM/Alltouch 2>/dev/null
    ;;
*)
    Pstream/Allwmake $targetType $*

    # Update version info (as required)
    OpenFOAM/Alltouch -check 2>/dev/null
    ;;
esac

wmake $targetType OpenFOAM

wmake $targetType fileFormats
wmake $targetType surfMesh
wmake $targetType meshTools

wmake $targetType finiteArea
wmake $targetType finiteVolume
wmake $targetType genericPatchFields
wmake $targetType mesh/extrudeModel
wmake $targetType dynamicMesh

wmake $targetType parallel/decompose/decompositionMethods

# Make dummy decomposition methods (dummyThirdParty)
parallel/decompose/AllwmakeLnInclude
dummyThirdParty/Allwmake $targetType $*

wmakeLnInclude -u fvOptions

wmake $targetType lagrangian/basic
wmake $targetType lagrangian/distributionModels

parallel/Allwmake $targetType $*

wmake $targetType dynamicFvMesh
wmake $targetType topoChangerFvMesh

wmake $targetType sampling
transportModels/Allwmake $targetType $*
randomProcesses/Allwmake $targetType $*

wmake $targetType ODE


thermophysicalModels/Allwmake $targetType $*
TurbulenceModels/Allwmake $targetType $*
wmake $targetType combustionModels
regionModels/Allwmake $targetType $*
lagrangian/Allwmake $targetType $*

wmake $targetType fvOptions
wmake $targetType fvMotionSolver

# Ensure we have block.H accessible before building overset
wmake $targetType mesh/blockMesh
wmake $targetType overset

# snappyHexMesh uses overset voxelMesh
mesh/Allwmake $targetType $*
renumber/Allwmake $targetType $*
fvAgglomerationMethods/Allwmake $targetType $*
wmake $targetType waveModels

wmake $targetType engine

conversion/Allwmake $targetType $*

functionObjects/Allwmake $targetType $*
phaseSystemModels/Allwmake $targetType $*

wmake $targetType lumpedPointMotion
wmake $targetType sixDoFRigidBodyMotion
wmake $targetType sixDoFRigidBodyState
wmake $targetType rigidBodyDynamics
wmake $targetType rigidBodyMeshMotion
wmake $targetType semiPermeableBaffle
wmake $targetType atmosphericModels
wmake $targetType optimisation/adjointOptimisation/adjoint


# interfaceTracking libs
dynamicFaMesh/Allwmake $targetType $*


# Needs access to Turbulence

wmake $targetType thermophysicalModels/thermophysicalPropertiesFvPatchFields/liquidProperties

#------------------------------------------------------------------------------
